<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Incorporating static relevance signals into the score | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'static-scoring-signals.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/static-scoring-signals.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/static-scoring-signals.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/static-scoring-signals.html" rel="nofollow" target="_blank">../en/static-scoring-signals.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="how-to.html">How To</a></span>
»
<span class="breadcrumb-link"><a href="recipes.html">Recipes</a></span>
»
<span class="breadcrumb-node">Incorporating static relevance signals into the score</span>
</div>
<div class="navheader">
<span class="prev">
<a href="consistent-scoring.html">« Getting consistent scoring</a>
</span>
<span class="next">
<a href="tune-for-indexing-speed.html">Tune for indexing speed »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="static-scoring-signals"></a>Incorporating static relevance signals into the score<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/how-to/recipes/scoring.asciidoc">edit</a>
</h2>
</div></div></div>
<p>Many domains have static signals that are known to be correlated with relevance.
For instance <a href="https://en.wikipedia.org/wiki/PageRank" class="ulink" target="_top">PageRank</a> and url length are
two commonly used features for web search in order to tune the score of web
pages independently of the query.</p>
<p>There are two main queries that allow combining static score contributions with
textual relevance, eg. as computed with BM25:
 - <a class="xref" href="query-dsl-script-score-query.html" title="Script score query"><code class="literal">script_score</code> query</a>
 - <a class="xref" href="query-dsl-rank-feature-query.html" title="Rank feature query"><code class="literal">rank_feature</code> query</a></p>
<p>For instance imagine that you have a <code class="literal">pagerank</code> field that you wish to
combine with the BM25 score so that the final score is equal to
<code class="literal">score = bm25_score + pagerank / (10 + pagerank)</code>.</p>
<p>With the <a class="xref" href="query-dsl-script-score-query.html" title="Script score query"><code class="literal">script_score</code> query</a> the query would
look like this:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET index/_search
{
    "query" : {
        "script_score" : {
            "query" : {
                "match": { "body": "elasticsearch" }
            },
            "script" : {
                "source" : "_score * saturation(doc['pagerank'].value, 10)" <a id="CO543-1"></a><i class="conum" data-value="1"></i>
            }
        }
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1305.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO543-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p><code class="literal">pagerank</code> must be mapped as a <a class="xref" href="number.html" title="Numeric datatypes">Numeric</a></p>
</td>
</tr>
</table>
</div>
<p>while with the <a class="xref" href="query-dsl-rank-feature-query.html" title="Rank feature query"><code class="literal">rank_feature</code> query</a> it would
look like below:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET _search
{
    "query" : {
        "bool" : {
            "must": {
                "match": { "body": "elasticsearch" }
            },
            "should": {
                "rank_feature": {
                    "field": "pagerank", <a id="CO544-1"></a><i class="conum" data-value="1"></i>
                    "saturation": {
                        "pivot": 10
                    }
                }
            }
        }
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1306.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO544-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p><code class="literal">pagerank</code> must be mapped as a <a class="xref" href="rank-feature.html" title="Rank feature datatype"><code class="literal">rank_feature</code></a> field</p>
</td>
</tr>
</table>
</div>
<p>While both options would return similar scores, there are trade-offs:
<a class="xref" href="query-dsl-script-score-query.html" title="Script score query">script_score</a> provides a lot of flexibility,
enabling you to combine the text relevance score with static signals as you
prefer. On the other hand, the <a class="xref" href="rank-feature.html" title="Rank feature datatype"><code class="literal">rank_feature</code> query</a> only
exposes a couple ways to incorporate static signails into the score. However,
it relies on the <a class="xref" href="rank-feature.html" title="Rank feature datatype"><code class="literal">rank_feature</code></a> and
<a class="xref" href="rank-features.html" title="Rank features datatype"><code class="literal">rank_features</code></a> fields, which index values in a special way
that allows the <a class="xref" href="query-dsl-rank-feature-query.html" title="Rank feature query"><code class="literal">rank_feature</code> query</a> to skip
over non-competitive documents and get the top matches of a query faster.</p>
</div>
<div class="navfooter">
<span class="prev">
<a href="consistent-scoring.html">« Getting consistent scoring</a>
</span>
<span class="next">
<a href="tune-for-indexing-speed.html">Tune for indexing speed »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>